package com.wgts.wgts.mvp.view.activity.timeaction;

import android.app.Activity;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.wgts.wgts.R;
import com.wgts.wgts.control.viewpage.ComFragmentAdapter;
import com.wgts.wgts.control.viewpage.WrapContentHeightViewPager;
import com.wgts.wgts.test.TestViewPageFragment;

import net.lucode.hackware.magicindicator.MagicIndicator;

import java.util.ArrayList;

public class TimeActionAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {


    private static final int TITLE = 0x0001;

    private static final int TITLE_TIME = 0x0002;

    private static final int VIEW_HOLDER = 0x0003;

    private Context context;

    private ArrayList<String> arrayList;

    private  FragmentManager fragmentManager;

    public TimeActionAdapter(Context context, ArrayList<String> arrayList, FragmentManager fragmentManager) {
        this.context = context;
        this.arrayList = arrayList;
        this.fragmentManager = fragmentManager;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        switch (i){
            case TITLE:
                return new TimeActionTitleViewHolder(LayoutInflater.from(context).inflate(R.layout.new_people_title_view_holder, viewGroup, false));
            case VIEW_HOLDER:
                return new TimeActionViewHolder(LayoutInflater.from(context).inflate(R.layout.time_action_fragment_view_holder, viewGroup, false));
                default:
                    return null;
        }
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {

    }

    @Override
    public int getItemCount() {
        return arrayList.size();
    }

    public class TimeActionTitleViewHolder extends RecyclerView.ViewHolder {
        public TimeActionTitleViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }



    public class TimeActionViewHolder extends RecyclerView.ViewHolder {
        public WrapContentHeightViewPager viewPager;

        public MagicIndicator magicIndicator;

        public TimeActionViewHolder(@NonNull View itemView) {
            super(itemView);
            viewPager = itemView.findViewById(R.id.view_page);
            magicIndicator = itemView.findViewById(R.id.magic_indicator);

            ArrayList<Fragment> fragments = new ArrayList<>();

            for (int i = 0; i < 10; i++) {
                fragments.add(new TestViewPageFragment());
            }

            viewPager.setAdapter(new ComFragmentAdapter(fragmentManager, fragments));
        }
    }

    @Override
    public int getItemViewType(int position){
        if(isTitle(position)){
            return TITLE;
        }
        return VIEW_HOLDER;
    }

    private boolean isTitle(int postion){
        if(postion == 0){
            return true;
        }
        return false;
    }



    private boolean isViewHolder(int postion){
        if(postion != 0 && postion != 1){
            return true;
        }
        return false;
    }
}
